package com.tydic.system.controller.system;

import com.tydic.common.core.domain.R;
import com.tydic.common.core.domain.model.LoginUser;
import com.tydic.common.core.enums.EnableEnum;
import com.tydic.common.core.validate.QueryGroup;
import com.tydic.common.mybatis.core.page.TableDataInfo;
import com.tydic.common.satoken.utils.LoginHelper;
import com.tydic.system.domain.SysMessage;
import com.tydic.system.domain.bo.QuerySysMessageBo;
import com.tydic.system.service.ISysMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/message")
@RequiredArgsConstructor
@Slf4j
public class SysMessageController {

    private final ISysMessageService sysMessageService;

    /**
     * 获取消息
     *
     * @param bo
     * @return
     */
    @PostMapping("getMessage")
    public R<TableDataInfo<SysMessage>> getMessage(@Validated(QueryGroup.class) @RequestBody QuerySysMessageBo bo) {
        LoginUser loginUser = LoginHelper.getLoginUser();
        String userCode = loginUser.getUserCode();
        bo.setReceiver(userCode);
        bo.setViewStatus(EnableEnum.DISABLE.getStatus());
        return R.ok(TableDataInfo.build(sysMessageService.selectPage(bo)));
    }

}
